home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / EasyPHP-2.0b1-setup.exe / {app} / phpmyadmin / libraries / session.inc.php < prev    next >
Encoding:
PHP Script  |  2006-11-18  |  3.6 KB  |  112 lines

  1. <?php
  2. /* $Id: session.inc.php 9619 2006-10-26 15:25:28Z lem9 $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4. /**
  5.  * session handling
  6.  *
  7.  * @TODO    add failover or warn if sessions are not configured properly
  8.  * @TODO    add an option to use mm-module for session handler
  9.  * @see     http://www.php.net/session
  10.  * @uses    session_name()
  11.  * @uses    session_start()
  12.  * @uses    ini_set()
  13.  * @uses    version_compare()
  14.  * @uses    PHP_VERSION
  15.  */
  16.  
  17. // verify if PHP supports session, die if it does not
  18.  
  19. if (!@function_exists('session_name')) {
  20.     $cfg = array('DefaultLang'           => 'en-iso-8859-1',
  21.                  'AllowAnywhereRecoding' => false);
  22.     // Loads the language file
  23.     require_once('./libraries/select_lang.lib.php');
  24.     // Displays the error message
  25.     // (do not use & for parameters sent by header)
  26.     header('Location: error.php'
  27.             . '?lang='  . urlencode($available_languages[$lang][2])
  28.             . '&dir='   . urlencode($text_dir)
  29.             . '&type='  . urlencode($strError)
  30.             . '&error=' . urlencode(sprintf($strCantLoad, 'session')));
  31.     exit();
  32. } elseif (ini_get('session.auto_start') == true && session_name() != 'phpMyAdmin') {
  33.     $_SESSION = array();
  34.     if (isset($_COOKIE[session_name()])) {
  35.         setcookie(session_name(), '', time()-42000, '/');
  36.     }
  37.     session_unset();
  38.     @session_destroy();
  39. }
  40.  
  41. // disable starting of sessions before all settings are done
  42. // does not work, besides how it is written in php manual
  43. //ini_set('session.auto_start', 0);
  44.  
  45. // session cookie settings
  46. session_set_cookie_params(0, PMA_Config::getCookiePath(),
  47.     '', PMA_Config::isHttps());
  48.  
  49. // cookies are safer
  50. ini_set('session.use_cookies', true);
  51.  
  52. // but not all user allow cookies
  53. ini_set('session.use_only_cookies', false);
  54. ini_set('session.use_trans_sid', true);
  55. ini_set('url_rewriter.tags',
  56.     'a=href,frame=src,input=src,form=fakeentry,fieldset=');
  57. //ini_set('arg_separator.output', '&');
  58.  
  59. // delete session/cookies when browser is closed
  60. ini_set('session.cookie_lifetime', 0);
  61.  
  62. // warn but dont work with bug
  63. ini_set('session.bug_compat_42', false);
  64. ini_set('session.bug_compat_warn', true);
  65.  
  66. // use more secure session ids (with PHP 5)
  67. if (version_compare(PHP_VERSION, '5.0.0', 'ge')
  68.   && substr(PHP_OS, 0, 3) != 'WIN') {
  69.     ini_set('session.hash_function', 1);
  70.     ini_set('session.hash_bits_per_character', 6);
  71. }
  72.  
  73. // start the session
  74. // on some servers (for example, sourceforge.net), we get a permission error
  75. // on the session data directory, so I add some "@"
  76.  
  77. // [2006-01-25] Nicola Asuni - www.tecnick.com: maybe the PHP directive
  78. // session.save_handler is set to another value like "user"
  79. ini_set('session.save_handler', 'files');
  80.  
  81. @session_name('phpMyAdmin');
  82. @session_start();
  83.  
  84. /**
  85.  * Token which is used for authenticating access queries.
  86.  * (we use "space PMA_token space" to prevent overwriting)
  87.  */
  88. if (!isset($_SESSION[' PMA_token '])) {
  89.     $_SESSION[' PMA_token '] = md5(uniqid(rand(), true));
  90. }
  91.  
  92. /**
  93.  * trys to secure session from hijacking and fixation
  94.  * should be called before login and after successfull login
  95.  * (only required if sensitive information stored in session)
  96.  *
  97.  * @uses    session_regenerate_id() to secure session from fixation
  98.  * @uses    session_id()            to set new session id
  99.  * @uses    strip_tags()            to prevent XSS attacks in SID
  100.  * @uses    function_exists()       for session_regenerate_id()
  101.  */
  102. function PMA_secureSession()
  103. {
  104.     // prevent session fixation and XSS
  105.     if (function_exists('session_regenerate_id')) {
  106.         session_regenerate_id(true);
  107.     } else {
  108.         session_id(strip_tags(session_id()));
  109.     }
  110. }
  111. ?>
  112.